#encoding=utf8
'''
Created on 2012-10-17

@author: Administrator
'''
from Processor import Processor
from models import MessagesModel,Messages;
from pub import Func, UserDict;
from pub.Config import Config

class UFFAClass(Processor):
    '''
    指令：UFFA(user friend first add)
    备注：添加好友
    格式：c-s:cmd #cmdID#userIDSend#userIDTo#infos
     s-c:cmd #cmdID#userIdTo#userIdSend#userIDFromuserNickName# infos
    '''
    def __init__(self,):
        Processor.__init__(self);
        self.__userIdSend = 0;
        self.__userIdTo=0;
        self.__infos="";         
        
    def dataValidtor(self, cmdContent):
        if not cmdContent:
            return False;
        paraLen = len(cmdContent);
        if paraLen == 3:      
            self.__userIdSend = Func.strToInt(cmdContent[0], Config.I_SYS_ZERO);
            self.__userIdTo = Func.strToInt(cmdContent[1], Config.I_SYS_ZERO);
            self.__infos = Func.toStr(cmdContent[2]);            
            return True;        
        return False;
    def outData(self,):
        userSend=UserDict.getUserFromUserDictById(self.__userIdSend);
        if not userSend:
            return False;
        userNickNameSend=userSend.get_user_nick_name();
        userTo=UserDict.getUserFromUserDictById(self.__userIdTo);
        
        messagesM=MessagesModel();
        messages=Messages();
        messages.set_title("好友验证");
        messages.get_msgtype(3);
        messages.set_msg_sender(self.__userIdSend);
        messages.set_msg_reciever(self.__userIdTo);
        messages.set_content(self.__infos);
        now=Func.getNow();
        messages.set_created(now);
        sendMsg=[messages.get_title(),3,now,messages.get_msg_sender(),userNickNameSend,0,"","",self.__infos];
        if userTo:#用户在线
            messages.set_msg_sended(Config.I_SYS_ONE);
            messages.set_msg_state(Config.I_SYS_ONE);           
            Func.sendMsg(sockObj=userTo.get_socket(), cmd=Config.CommandMap["PIS"][0], cmdId=0, Message=sendMsg);#发送加好友消息           
            
        messagesM.addNewMessage(messages);        
        
        
        
          